﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using GabageFactory.Models;

namespace GabageFactory.Controllers
{
    [HandleError]
    [Authorize]
    public class HomeController : BaseController
    {
        private FactoryReposity factoryReposity = new FactoryReposity();

        private MessageReposity messageReposity = new MessageReposity();
        
        public ActionResult Index()
        {
            ViewData["Message"] = "Welcome to ASP.NET MVC!";

            return View();
        }

        public ActionResult Separator()
        {
            return View();
        }

        public ActionResult Top()
        {
            User user = GetCurrentUser();
            ViewData["user"] = user;

            return View();
        }

        [Authorize]
        public ActionResult Message()
        {
            User user = GetCurrentUser();
            IEnumerable<Message> messages = messageReposity.AquireMessages(user.FactoryId);
            Message[] messageArray = new Message[0];
            if (messages != null && messages.Count() > 0)
            {
                messageArray = messages.ToArray();
            }
            ViewData["messages"] = messageArray;

            return View();
        }

        [Authorize]
        public ActionResult LeftMenu()
        {
            User user = GetCurrentUser();
            ViewData["user"] = user;
            ViewData["factories"] = factoryReposity.ListFactories();
            return View();
        }

        public ActionResult About()
        {
            return View();
        }

        public ActionResult Deny()
        {
            return View();
        }
    }
}
